package com.smartbus.bus.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.smartbus.common.annotation.Log;
import com.smartbus.common.core.controller.BaseController;
import com.smartbus.common.core.domain.AjaxResult;
import com.smartbus.common.enums.BusinessType;
import com.smartbus.bus.domain.ExceptionLogs;
import com.smartbus.bus.service.IExceptionLogsService;
import com.smartbus.common.utils.poi.ExcelUtil;
import com.smartbus.common.core.page.TableDataInfo;

/**
 * 系统异常日志，记录GPS丢失、语音播放失败等异常情况及处理过程Controller
 * 
 * @author ruoyi
 * @date 2025-09-24
 */
@RestController
@RequestMapping("/bus/exception-logs")
public class ExceptionLogsController extends BaseController
{
    @Autowired
    private IExceptionLogsService exceptionLogsService;

    /**
     * 查询系统异常日志，记录GPS丢失、语音播放失败等异常情况及处理过程列表
     */
    @PreAuthorize("@ss.hasPermi('bus:logs:list')")
    @GetMapping("/list")
    public TableDataInfo list(ExceptionLogs exceptionLogs)
    {
        startPage();
        List<ExceptionLogs> list = exceptionLogsService.selectExceptionLogsList(exceptionLogs);
        return getDataTable(list);
    }

    /**
     * 导出系统异常日志，记录GPS丢失、语音播放失败等异常情况及处理过程列表
     */
    @PreAuthorize("@ss.hasPermi('bus:logs:export')")
    @Log(title = "系统异常日志，记录GPS丢失、语音播放失败等异常情况及处理过程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExceptionLogs exceptionLogs)
    {
        List<ExceptionLogs> list = exceptionLogsService.selectExceptionLogsList(exceptionLogs);
        ExcelUtil<ExceptionLogs> util = new ExcelUtil<ExceptionLogs>(ExceptionLogs.class);
        util.exportExcel(response, list, "系统异常日志，记录GPS丢失、语音播放失败等异常情况及处理过程数据");
    }

    /**
     * 获取系统异常日志，记录GPS丢失、语音播放失败等异常情况及处理过程详细信息
     */
    @PreAuthorize("@ss.hasPermi('bus:logs:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(exceptionLogsService.selectExceptionLogsById(id));
    }

    /**
     * 新增系统异常日志，记录GPS丢失、语音播放失败等异常情况及处理过程
     */
    @PreAuthorize("@ss.hasPermi('bus:logs:add')")
    @Log(title = "系统异常日志，记录GPS丢失、语音播放失败等异常情况及处理过程", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExceptionLogs exceptionLogs)
    {
        return toAjax(exceptionLogsService.insertExceptionLogs(exceptionLogs));
    }

    /**
     * 修改系统异常日志，记录GPS丢失、语音播放失败等异常情况及处理过程
     */
    @PreAuthorize("@ss.hasPermi('bus:logs:edit')")
    @Log(title = "系统异常日志，记录GPS丢失、语音播放失败等异常情况及处理过程", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExceptionLogs exceptionLogs)
    {
        return toAjax(exceptionLogsService.updateExceptionLogs(exceptionLogs));
    }

    /**
     * 删除系统异常日志，记录GPS丢失、语音播放失败等异常情况及处理过程
     */
    @PreAuthorize("@ss.hasPermi('bus:logs:remove')")
    @Log(title = "系统异常日志，记录GPS丢失、语音播放失败等异常情况及处理过程", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(exceptionLogsService.deleteExceptionLogsByIds(ids));
    }
}
